package com.atguigu.lease.web.admin.controller.apartment;


import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.model.entity.FacilityInfo;
import com.atguigu.lease.model.enums.ItemType;
import com.atguigu.lease.web.admin.service.FacilityInfoService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Package: com.atguigu.lease.web.admin.controller.apartment
 *
 * @Description:
 * @Author xiongkunYang
 * @Create 2025/4/19 23:06
 */
@Tag(name = "配套管理")
@RestController
@RequestMapping("/admin/facility")
public class FacilityController {

    private final FacilityInfoService facilityInfoService;

    public FacilityController(FacilityInfoService facilityInfoService) {
        this.facilityInfoService = facilityInfoService;
    }

    @Operation(summary = "[根据类型]查询配套信息列表")
    @GetMapping("list")
    public Result<List<FacilityInfo>> listFacility(@RequestParam(required = false) ItemType type) {
        List<FacilityInfo> facilityInfoList = this.facilityInfoService
                .list(new LambdaQueryWrapper<FacilityInfo>()
                .eq(type != null, FacilityInfo::getType, type));
        return Result.ok(facilityInfoList);
    }

    @Operation(summary = "新增或修改配套信息")
    @PostMapping("saveOrUpdate")
    public Result<Boolean> saveOrUpdate(@RequestBody FacilityInfo facilityInfo) {
        return Result.ok(this.facilityInfoService.saveOrUpdate(facilityInfo));
    }

    @Operation(summary = "根据id删除配套信息")
    @DeleteMapping("deleteById")
    public Result<Boolean> removeFacilityById(@RequestParam Long id) {
        return Result.ok(this.facilityInfoService.removeById(id));
    }

}
